kd = input() 
if len(kd) != 4 or not kd.isdigit(): 
    print(0) 
else: 
    lv = 0 
    for i in range(4): 
        for j in range(i + 1, 5): 
            num = int(kd[i:j]) 
            re = True 
            if num <= 1: 
                re = False 
            else: 
                for h in range(2, int(num**0.5) + 1): 
                    if num % h == 0: 
                        re = False 
                        break 
            if re and num > lv: 
                lv = num
    print(lv)
